package pcgen.android.app;

import android.os.Bundle;
import android.preference.PreferenceActivity; 

import pcgen.android.DefaultSharedPreferences;
import pcgen.android.Logger;

public abstract class DefaultPreferenceActivity<T> extends PreferenceActivity
{
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		try
		{
			super.onCreate(savedInstanceState);
			
			addPreferencesFromResource(getLayoutId());
		}
		catch (Throwable tr)
		{
			Logger.e(TAG, "onCreate", tr);
		}
	}
	
	@Override
    protected void onPause()
	{
		try
		{
			DefaultSharedPreferences.commit(this.getBaseContext());

	    	super.onPause();
		}
		catch (Throwable tr)
		{
			Logger.e(TAG, "onSaveInstanceState", tr);
		}
    }
	
	protected abstract int getLayoutId();
	
	@SuppressWarnings("unchecked")
	protected T getApplicationEx()
	{
		return (T)getApplication();
	}
	
	private static final String TAG = DefaultPreferenceActivity.class.getSimpleName();
}
